<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>提现管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <!-- <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" /> -->
        
        <link rel="stylesheet" href="/static/temp/layui/css/layui.css"  media="all">

        <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" href="/static/temp/css/font.css">
        <link rel="stylesheet" href="/static/temp/css/xadmin.css">
        
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <script type="text/javascript" src="/static/temp/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/temp/js/xadmin.js"></script>
    </head>
<body>
    <div style="padding: 20px">
        <div class="demoTable">
            <form class="layui-form">
                <div class="layui-inline">
                    <input class="layui-input" name="start" id="start" autocomplete="off" placeholder="申请时间（开始）">
                </div>

                <div class="layui-inline">
                    <input class="layui-input" name="end" id="end" autocomplete="off" placeholder="申请时间（结束）">
                </div>

                <div class="layui-inline">
                    <input class="layui-input" name="real_name" id="real_name" autocomplete="off" placeholder="搜索真实姓名">
                </div>

                <div class="layui-input-inline">
                    <select name="status" id="status">
                        <option value="">提现状态</option>
                        <option value="1">待审核</option>
                        <option value="2">已通过</option>
                        <option value="3">已拒绝</option>
                    </select>
                </div>

                <div class="layui-input-inline">
                    <select name="admin_id" id="admin_id">
                        <option value="">所属门店</option>
                        {foreach $admin_list as $k => $v}
                        <option value="{$v.id}">{$v.nickname}</option>
                        {/foreach}
                    </select>
                </div>

                <button class="layui-btn" type="button" id="seach">搜索</button>
            </form>
        </div>
    
        <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>
 
    <script type="text/html" id="barDemo">
        {{# if(d.status == '<span style="color:red">待审核</span>'){}}
        <a class="layui-btn layui-btn-xs" lay-event="pass">通过</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="back">驳回</a>
        {{# } }}
    </script>

    <script>
        var page = 1;
        $(function(){
            if(window.location.href.includes('#!true=')){
                page = window.location.href.split('#!true=')[1];
            }
        })

        layui.use(['table', 'laydate'], function(){
            var table = layui.table
                , laydate = layui.laydate;
            
            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });

            function getList(){
                table.render({
                    elem: '#test'
                    ,url:'{:url("Cash/cash_data")}'
                    ,toolbar: true // 开启头部工具栏
                    ,defaultToolbar: ['filter', 'exports', 'print']
                    ,title: '提现数据表'
                    ,where: {
                        key: {
                            real_name: $('#real_name').val()
                            , status: $('#status').val()
                            , start: $('#start').val()
                            , end: $('#end').val()
                            , admin_id: $('#admin_id').val()
                        }
                    }
                    ,cols: [[
                        {field:'id', title:'ID', fixed: 'left', width: 80, unresize: true, sort: true}
                        ,{field:'admin_name', title:'所属门店'}
                        ,{field:'nickname', title:'申请人'}
                        ,{field:'real_name', title:'真实姓名'}
                        ,{field:'bank_number', title:'银行卡号'}
                        ,{field:'bank_name', title:'归属银行'}
                        ,{field:'number', title:'数量', width: 80, sort: true}
                        ,{field:'status', title:'状态', width: 80, sort: true}
                        ,{field:'fail_msg', title:'驳回原因'}
                        ,{field:'create_time', title:'申请时间'}
                        ,{fixed: 'right', title:'操作', width: 120, toolbar: '#barDemo'}
                    ]]
                    ,page: {
                        curr: page,
                        hash: true
                    }
                });
            }

            getList()

            $("#seach").on('click',function(){
                getList()
            })
          
            // 监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                console.log(obj)
                if(obj.event === 'back'){
                    layer.prompt({
                        formType: 2
                        ,title: data.real_name +'的提现驳回'
                    }, function(value, index){
                        //这里一般是发送修改的Ajax请求
                        $.post('{:url("Cash/cash_back")}',{
                            id: obj.data.id
                            , fail_msg: value
                        },function(res){
                            if(res.code == 400){
                                layer.msg(res.msg, {icon: 2});
                            }else{
                                layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                    // getList();
                                    window.location.reload()
                                }, 1000);
                            }
                        })

                        layer.close(index);
                    });

                    // 同步更新表格和缓存对应的值
                    // obj.update({
                    //     fail_msg: value
                    //     , status: '<span style="color:#ccc">已驳回</span>'
                    //     , button: ''
                    // });
                }else if(obj.event == 'pass'){
                    layer.confirm('确定要通过吗？', function(index){
                        $.post('{:url("Cash/cash_pass")}',{
                            id: obj.data.id
                        },function(res){
                            if(res.code == 400){
                                layer.msg(res.msg, {icon: 2});
                            }else{
                                layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                    window.location.reload()
                                }, 1000);
                            }
                        })

                        layer.close(index);
                    });
                }
            });
        });
    </script>
</body>
</html>